package com.elitedatai.mchtest.manage.repository;

import com.elitedatai.mchtest.manage.model.entity.DeviceLogsEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;


public interface DeviceLogsRepository extends JpaRepository<DeviceLogsEntity, Long> {

    @Query("SELECT d FROM DeviceLogsEntity d " +
            "WHERE d.deviceSn = :deviceSn " +
            "AND (:beginTime IS NULL OR :endTime IS NULL OR d.createTime BETWEEN :beginTime AND :endTime) " +
            "AND (:status IS NULL OR d.status = :status) " +
            "AND (:logsInformation IS NULL OR :logsInformation = '' OR d.logsInfo LIKE CONCAT('%', :logsInformation, '%'))")
    Page<DeviceLogsEntity> query(String deviceSn, Long beginTime, Long endTime, Integer status, String logsInformation, Pageable pageable);

    void deleteByLogsIdAndDeviceSn(String logsId, String deviceSn);

    DeviceLogsEntity findByLogsId(String logsId);
}
